package com.shuaiche.yeguan.views.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.shuaiche.yeguan.R;

public class LoadingDialog extends Dialog {

    private String loadingText;
    public LoadingDialog(Context context) {
        super(context, R.style.LoadingDialogStyle);
    }

    public LoadingDialog(Context context,String loadingText) {
        super(context, R.style.LoadingDialogStyle);
        this.loadingText = loadingText;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_loading);

        TextView tv_loading_text = findViewById(R.id.tv_loading_text);
        if (!TextUtils.isEmpty(loadingText)){
            tv_loading_text.setText(loadingText);
        }
        // 设置对话框属性
        Window window = getWindow();
        if (window != null) {
            WindowManager.LayoutParams params = window.getAttributes();
            params.gravity = Gravity.CENTER;
            params.width = WindowManager.LayoutParams.MATCH_PARENT;
            params.height = WindowManager.LayoutParams.MATCH_PARENT;
            window.setAttributes(params);
            window.setBackgroundDrawableResource(android.R.color.transparent);
        }
        setCancelable(false);
    }
}
